package cn.jietuo.juc.c_013_reftypeAndThreadLocal;

import java.lang.ref.WeakReference;
import java.util.WeakHashMap;
import java.util.concurrent.TimeUnit;

/**
 * @author zhangx & jietuo_zx@163.com
 * @version 1.0
 * @date 2020/5/11
 * @description:
 * 弱引用只要垃圾回收，就会回收
 * 一般用在容器中
 */
public class T03_WeakReference {

    public static void main(String[] args) {
        WeakReference<M> m = new WeakReference<>(new M());
        System.out.println(m.get());
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.gc();

        System.out.println(m.get());


        ThreadLocal<M> threadLocal = new ThreadLocal<>();
        threadLocal.set(new M());
    }
}
